{include file="common:header" /}
{include file="common:side" /}
    <div id="page-wrapper">
      <!-- 舆情日报 -->
      <!--*************************** content部分开始 ******************-->
      <div class="container-fluid" id="m_main">
        <div class="row m-t-20">
          <div class="col-sm-12">
            <div class="white-box">
              <h2 class="box-title m-b-20">活动图片管理</h2>
              <div class="row">
                <div class="col-sm-4">
                  <div class="form-group">
                    <label class="control-label">活动标题：</label>
                    <input type="text" class="form-control" placeholder="" v-model="activity.title">
                  </div>
                </div>
              </div>
              <div class="row">
                <div class="col-sm-4">
                  <div class="form-group">
                    <label class="control-label m-r-30">内容类型：</label>
                    <div class="radio radio-primary di m-r-30">
                      <input type="radio" name="type" v-model="activity.type" value="1" id="item_0">
                      <label for="item_0">链接</label>
                    </div>
                    <div class="radio radio-primary di">
                      <input type="radio" name="is_purchase" v-model="activity.type" value="0" id="item_1">
                      <label for="item_1">图文</label>
                    </div>
                  </div>
                </div>
              </div>
              <div class="row" v-if="activity.type == 1">
                <div class="col-sm-4">
                  <div class="form-group">
                    <label class="control-label">链接：</label>
                    <input type="text" class="form-control" placeholder="" v-model="activity.link">
                  </div>
                </div>
              </div>
              <div class="row">
                <div class="col-sm-4">
                  <div class="form-group m-addsku-pics">
                    <label class="control-label">活动图片：(750px*200px)</label>
                    <div>
                      <label for="add_activity_info_pic" class="btn btn-primary waves-effect waves-light" style="line-height: 20px;padding: 6px 10px">添加图片</label>
                      <input type="file" id="add_activity_info_pic" name="file" class="addpics" data-amount="1"/>
                      <div class="col-md-12">
                        <div id="activity_info_pic_box" class="pic-box"></div>
                        <input type="hidden" name="activity_info_pic" class="add-pic" id="activity_info_pic" value="" data-id="">
                        <input type="hidden" name="delete_activity_info_pic" class="delete-pic" id="delete_activity_info_pic">
                      </div>
                    </div>
                  </div>
                </div>
              </div>
              <div class="row">
                <div class="col-sm-6">
                  <div class="form-group">
                    <label class="control-label">活动详情：</label>
                    <!-- 加载编辑器的容器 -->
	                  <script id="contents-box" name="content" type="text/plain"></script>
                    <!-- <textarea class="form-control" placeholder="请输入..." v-model="activity.content">{{activity.content}}</textarea> -->
                  </div>
                </div>
              </div>
              <div class="row m-t-40">
                <div class="col-sm-8 ta-c">
                  <button type="button" name="" class="btn btn-outline btn-primary m-r-40" @click="doSubmit()">提交</button>
                </div>
              </div>
            </div>
          </div>
        </div>

        <!-- /.row -->
      </div>
      <!--*************************** content部分结束 ******************-->

      <!-- <footer class="footer text-center"> 2017 &copy; Ample Admin brought to you by themedesigner.in </footer> -->
    </div>
  {include file="common:js" /}
  {include file="common:footer" /}
  <script type="text/javascript" src="/web/uedit/ueditor.config.js"></script>
  <script type="text/javascript" src="/web/uedit/ueditor.all.js"></script>
  <script src="/assets/plugins/bower_components/jQuery-File-Upload/js/vendor/jquery.ui.widget.js"></script>
  <script src="/assets/plugins/bower_components/jQuery-File-Upload/js/jquery.iframe-transport.js"></script>
  <script src="/assets/plugins/bower_components/jQuery-File-Upload/js/jquery.fileupload.js"></script>
  <script src="/web/js/edit.js"></script>
  <script>
  	$(function() {
  		upload_photo('#add_activity_info_pic','/dboard/upload/cover_upload');
  	});
  </script>

  <script type="text/javascript">
    var vm = new Vue({
      el: '#m_main',
      data() {
        return {
          sid: '{$sid}',
          activity: {},
          api: "",
        }
      },
      mounted() {
        // 初始化富文本编辑器
        var ue = UE.getEditor('contents-box');
        if(this.sid) {this.requestData()}
      },
      methods: {
        requestData() {
          let that = this;
          axios.post('/dboard/activity/infoData', {sid: that.sid},{headers: {'X-Requested-with':'XMLHttpRequest'}}).then(res => {
            // console.log(res);
            if(res.data.Code == 0){
              if(res.data.Data.activity) {
                that.activity = res.data.Data.activity;
                $("#contents-box").val(res.data.Data.activity.content);
                $("#activity_info_pic").val(res.data.Data.activity.pic+",");
                if($("#activity_info_pic").val().length != 0){
                  show_photo('#activity_info_pic');
                }
                // 初始化富文本编辑器
                var ue = UE.getEditor('contents-box');
                var str = $("#contents-box").val();
                ue.ready(function() {
                    ue.setContent(str,false);
                });
              }
            }else{
              alert(res.data.Msg)
            }
          }).catch(err => {
            console.log(err);
          })
        },
        // 提交
        doSubmit(){
          var that = this;
          var param = {
            sid: that.sid,
            title: that.activity.title,
            link: that.activity.link,
            type: that.activity.type,
            content: UE.getEditor('contents-box').getContent(),
          }
          var activityStr = $('#activity_info_pic').val();
          var activityArray = activityStr.split(",");
          activityArray.splice(activityArray.length-1, 1);
          if(activityArray.length>0) { param.pic = activityArray[0] };
          if(activityArray.length>1) { alert('活动图片最多上传1张');return false}

          if(that.activity.id) {
            param.aid = that.activity.id;
            that.api = "/dboard/activity/editActivityinfo";
          } else {
            that.api = "/dboard/activity/doCreateActivity";
          }
          axios.post(that.api, param,{headers: {'X-Requested-with':'XMLHttpRequest'}}).then(res => {
            // console.log(res);
            if(res.data.Code == 0){
              //请求成功
              alert(res.data.Msg);
              window.location.reload();
            }else{
              alert(res.data.Msg)
            }
          }).catch(err => {
            console.log(err);
          })
        }
      }
    })
  </script>
